package com.cizzy.favorite.controller;

import com.cizzy.favorite.common.Result;
import com.cizzy.favorite.entity.Favorite;
import com.cizzy.favorite.entity.dto.VideoDTO;
import com.cizzy.favorite.entity.vo.FavoriteRequest;
import com.cizzy.favorite.service.IFavoriteService;
import io.swagger.models.auth.In;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.cizzy.favorite.config.CizzyFinal.PAGE_SIZE;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author crissy-月下闲人
 * @since 2023-11-02
 */
@RestController
@RequestMapping("/favorite")
public class FavoriteController {
    @Resource
    private IFavoriteService favoriteService;

    @ResponseBody
    @PostMapping("favorite")
    public Result<Favorite> createFavorite(@RequestBody FavoriteRequest favoriteRequest) {
        System.out.println(favoriteRequest.toString());
        return favoriteService.createFavorite(favoriteRequest);
    }

    @ResponseBody
    @PostMapping("cancelFavorite")
    public Result<Favorite> cancelFavorite(@RequestBody FavoriteRequest favoriteRequest) {
        return favoriteService.cancelFavorite(favoriteRequest);
    }

    @ResponseBody
    @GetMapping("/isFavorited/{userId}/{videoId}")
    public Result<Boolean> isFavorited(@PathVariable("userId") Long userId, @PathVariable("videoId") Long videoId) {
        return favoriteService.isFavorited(userId, videoId);
    }

    @ResponseBody
    @GetMapping("/getFavoriteById/{userId}")
    public Result<List<VideoDTO>> getFavoriteById(@PathVariable("userId") Long userId) {
        return favoriteService.getFavoriteById(userId);
    }

    @ResponseBody
    @GetMapping("/getFavoritePageById/{userId}/{page}")
    public Result<List<VideoDTO>> getFavoritePageById(@PathVariable("userId") Long userId, @PathVariable("page") Integer page) {
        return favoriteService.getFavoritePageById(userId, page, PAGE_SIZE);
    }

//    @GetMapping("like/{id}")
//    public Result<String> toLike(@PathVariable("id") Long videoId) {
//        return favoriteService.toLike(videoId);
//    }
//
//    @PostMapping("getFavList")
//    public Result<List<VideoDTO>> getFavList() {
//        return favoriteService.getFavList();
//    }
}
